package com.dxm.controller;

import com.alibaba.fastjson.JSONObject;
import com.dxm.common.annotation.Log;
import com.dxm.common.base.controller.BaseController;
import com.dxm.common.utils.StringUtil;
import com.dxm.service.InstallmentPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/installmentplan")
public class InstallmentPlanController extends BaseController {
    @Autowired
    private InstallmentPlanService installmentPlanService;

    /**
     * @Author zhangxingshuai
     * @Description //TODO 根据支付编号和借据号查询还款计划
     * @Date 14:52 2021/6/25
     * @Param [order_no 支付编号, trans_no 借据号]
     * @return com.dxm.common.base.controller.BaseController.Result<java.lang.Object>
     **/
    @GetMapping("getData")
    public Result<Object> getData(String order_no, String trans_no) {
        if (StringUtil.isEmpty(order_no) || StringUtil.isEmpty(trans_no)) {
            return Error(HttpStatus.BAD_REQUEST,"支付编号或借据号不能为空！");
        }
        JSONObject result = installmentPlanService.getData(order_no, trans_no);
        String errno = result.getString("errno");
        String errmsg = result.getString("errmsg");
        JSONObject data = result.getJSONObject("data");
        if (!"0".equals(errno)) {
            return OK(errmsg);
        }
        return OK(data);
    }
}
